#pragma once

class EditBox;

class DLL_EXPORT UIManager : public Singleton<UIManager>
{
	std::set<UIElement*> m_elements;
	std::set<EditBox*> m_editBoxes;
	UIElement* m_pressedElem;
	bool m_enabled;
	bool m_uiHold;
	std::vector<CFont*> m_fonts;
public:
	UIManager();
	void Init();
	void Render();
	void AddElement(UIElement* pElement)
	{
		if(!pElement->m_isDialog)
			m_elements.insert(pElement);
		else
			DialogHandler::GetInstance()->AddDialog((Dialog*)pElement);
	}
	void RemoveElement(UIElement* pElement) { m_elements.erase(pElement); }
	void OnMouseMove(Vertex2F pos);
	bool OnMouseActivity(Vertex2F pos, bool up);
	void AddEditBox(EditBox* pBox) { m_editBoxes.insert(pBox); }
	void OnChar(char c);
	bool GetEditFocus();
	void Toggle() { m_enabled = !m_enabled; }
	bool IsUIHold() { return m_uiHold; }
	void OnReset()
	{
		for(ui32 i = 0; i < m_fonts.size(); ++i)
			m_fonts[i]->Recreate();
	}
	void BeforeReset()
	{
		for(ui32 i = 0; i < m_fonts.size(); ++i)
			m_fonts[i]->Release();
	}
	void AddFont(CFont* pFont) { m_fonts.push_back(pFont); }
};

#define sUI (*UIManager::GetInstance())